package com.training1.core.web.controller.lizeyu;

import java.util.ArrayList;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MapList {
	public static void main(String[] args) {
		Student s1=new Student();
		Student s2=new Student();
		Student s3=new Student();
		Student s4=new Student();
		Student s5=new Student();
		Student s6=new Student();
		s1.setId(1);s1.setName("张一");
		s2.setId(2);s2.setName("张二");
		s3.setId(3);s3.setName("张三");
		s4.setId(2);s4.setName("张二");
		s5.setId(1);s5.setName("张一");
		s6.setId(5);s6.setName("张五");
		List<Student>list=new ArrayList<>();
		list.add(s1);
		list.add(s2);
		list.add(s3);
		list.add(s4);
		list.add(s5);
		list.add(s6);

		Map<Integer,String>map=new HashMap<>();
		for(int i=0;i<list.size();i++){
			int count=0;//计数器
			for(Integer key:map.keySet()){//得到key值
				if(key==list.get(i).getId()){//判断key是否已存在
					break;
				}else{	
					count++;
				}
			}
			if(count==map.size()){//说明key不存在
				map.put(list.get(i).getId(), list.get(i).getName());//map赋值	
			}
		}
		list.clear();
		for(Integer key:map.keySet()){//把map元素存入list中
			Student s=new Student();
			s.setId(key);
			s.setName(map.get(key));
			list.add(s);
		}
		for(int i=0;i<list.size();i++){
			System.out.println(list.get(i).getId()+"-->"+list.get(i).getName());
		}

	}
}
